<?php

namespace app\agent\controller;

use app\common\controller\Agent;
use app\common\model\Images;
use app\common\model\OrderAftersalesRecord;
use think\Db;
use think\Exception;

/**
 * 订单管理
 *
 * @icon fa fa-user
 */
class OrderAftersales extends Agent
{

    protected $relationSearch = true;
    protected $multiFields = 'status';

    protected $model = null;
    protected $agent_id = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = model('OrderAftersales');
        $agent_info = session('agent');
        $this->agent_id = $agent_info['id'];
    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();
            $list = $this->model->with(['member','shop','order'])->where($where)->where(['order_aftersales.agent_id'=>$this->agent_id])->order($sort, $order)->paginate($limit);
            $result = array("total" => $list->total(), "rows" => $list->items());
            return json($result);
        }
        return $this->view->fetch();
    }

    public function record($ids=null)
    {
        $list = OrderAftersalesRecord::where('order_aftersales_id',$ids)->order('createtime asc,id asc')->select()->toArray();
        $this->view->assign("list", $list);
        return $this->view->fetch();
    }


}
